package com.resifind.www.dao.impl;

import com.resifind.www.dao.AdminDao;
import com.resifind.www.dao.mapper.Mappers;
import com.resifind.www.po.Recharge;
import com.resifind.www.util.JdbcUtils;

import java.sql.Connection;
import java.util.List;

/**
 * @author 36069
 */
public class AdminDaoImpl implements AdminDao {

    @Override
    public boolean queryByPassword(String password) {
        //language=MySQL
        String sql = "select * from resi_find.admin where password = ?";
        Object[] params = {password};
        List<String> strings = JdbcUtils.query(sql, params, rs -> rs.getString("password"));
        return !strings.isEmpty();
    }

    @Override
    public List<Recharge> queryRecharge(String status) {
        //language=MySQL
        String sql = "select * from resi_find.recharge where status = ?";
        Object[] params = {status};
        return Mappers.rechargeMapper(sql, params);
    }

    @Override
    public boolean updateRechargeStatus(int rechargeId, String status, Connection conn) {
        //language=MySQL
        String sql = "update resi_find.recharge set status = ? where id = ?";
        Object[] params = {status, rechargeId};
        return JdbcUtils.update(sql, params, conn);
    }

}
